﻿using DZParallelLib.Data;
using System.IO;
using System.Xml.Serialization;

namespace DZParallelLib.Utility
{
    /// <summary>
    /// This class helps load in DZ files, which are the XML files that describe the
    /// DeepZoom collection.
    /// </summary>
    public static class DZIO
    {

        /// <summary>
        /// Load in the file info
        /// </summary>
        /// <param name="dzFile"></param>
        /// <returns></returns>
        static public Collection LoadDZ(FileInfo dzFile)
        {
            // Simple checks

            if (!dzFile.Exists)
                throw new FileNotFoundException("Couldn't open the DZ file", dzFile.FullName);

            // Load up the serializer and load in the file.
            var ser = new XmlSerializer(typeof(Collection));
            using (var rdr = dzFile.OpenRead())
            {
                return ser.Deserialize(rdr) as Collection;
            }
        }
    }
}
